package com.farm.system.exception;

import com.farm.constant.MessageConstant;
import com.farm.entity.Result;
import com.farm.entity.StatusCode;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 同一异常处理类
 *
 * @author Chengfei
 * @date 2020/10/12
 */
@ControllerAdvice
public class BaseExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result error(Exception e) {
        //打印错误,用于控制台分析
        e.printStackTrace();

        return new Result(false, StatusCode.ERROR, MessageConstant.EXECUTE_FAIL, e.getMessage());
    }
}
